package main

import (
	"langbase/goroutine/gonums/worker"
	"math/rand"
	"sync"
	"time"
)

func main() {
	rand.Seed(time.Now().Unix())
	go func() {
		ticker := time.NewTicker(time.Millisecond * 100)
		for true {
			select {
			case <-ticker.C:
				//log.Printf("当前开启协程数目：%d \n", runtime.NumGoroutine())
			}
		}
	}()

	taskChan := worker.CreateTask(10)
	//使用work阻塞，work处理完成之后，任务自然结束
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		//此处开启异步协程执行work方式，就可以开启多个work程序并行处理不同数据
		defer wg.Done()
		finishChan := worker.Work(taskChan, 3)
		<-finishChan
	}()

	wg.Wait()
}
